import os
from flask import Flask
from flask_cors import CORS

from applications.controllers import init_bps
from applications.common.utils.custom_json_encoder import MyJSONProvider
from applications.extensions import init_plugs
Flask.json_provider_class = MyJSONProvider
import logging
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('main')
from applications.room.room_manager import RoomManager
def create_app():
    app = Flask(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
    # 处理中文问题
    app.json.ensure_ascii = False
    # 处理跨域
    CORS(app)
    # 注册flask组件
    init_plugs(app)
    # 注册蓝图 (路由)
    init_bps(app)
    # 注册 websocket
    RoomManager(app)


    return app
